<div class="fieldsets">

<!-- Form: Filter activities by date -->
    <fieldset>
        <legend>Filter by date</legend>
        <%= render :partial => '/activities/calendar' %>
    </fieldset>   
<!-- End of form -->
 
<br/><br/>
   
<!-- Form: search -->

<% form_tag({:action => 'search', :id => @activity}) do %>
        <% params[:search]||= {} %>
		<fieldset style="width: 530px;">
        <legend>Search</legend>

        <table><tbody>
        <tr><td colspan="2">
        <%= radio_button_tag "search[is_invoiced]", "0", params[:search][:is_invoiced].to_i == 0, :id => 'search_is_invoiced_0' %><label for="search_is_invoiced_0">all</label>
        <%= radio_button_tag "search[is_invoiced]", "1", params[:search][:is_invoiced].to_i == 1, :id => 'search_is_invoiced_1' %><label for="search_is_invoiced_1">uninvoiced</label>
        <%= radio_button_tag "search[is_invoiced]", "2", params[:search][:is_invoiced].to_i == 2, :id => 'search_is_invoiced_2' %><label for="search_is_invoiced_2">invoiced</label>
        </td></tr>
        <tr><td><label>From:</label></td>
        <td><%= calendar_date_select_tag "search[date_from]", params[:search][:date_from] %></td></tr>
      
        <tr><td><label>To:</label></td>
        <td><%= calendar_date_select_tag "search[date_to]", params[:search][:date_to] %></td></tr>
        
        <tr><td><label for="search_project_id">Project:</label></td>
        <td><select name="search[project_id]" id="search_project_id" style="width:200px">
        <%= options_for_select({ "choose" => "" }) %>
        <%= options_for_select(Project.find(:all).collect{|p| [p.name + " - " + 
        	p.client.name, p.id ] }, params[:search][:project_id].to_i) %>
        </select></td></tr>
        
        <tr><td><label for="search_role_id">Role:</label></td>
        <td><select name="search[role_id]" id="search_role_id" style="width:200px">
        <%= options_for_select({ "choose" => "" }) %>
        <%= options_for_select(Role.find(:all,:order=>"name").collect {|r| [ r.name, r.id ] }, params[:search][:role_id].to_i ) %>
        </select></td></tr>
        
        <tr><td><label for="search_user_id">User:</label></td>
        <td><select name="search[user_id]" id="search_user_id" style="width:200px">
        <%= options_for_select({ "choose" => "" }) %>
        <%= options_for_select(User.find_active.collect {|u| [ u.name, u.id ] }, params[:search][:user_id].to_i ) %>
        </select></td></tr>

        <tr><td colspan="2">
        <br />
        <%= submit_tag 'Search' %>&nbsp;&nbsp;<%= submit_tag 'Generate graph' %>&nbsp;&nbsp;<%= submit_tag 'Export to CSV' %>
        &nbsp;&nbsp;<%= check_box_tag 'search[details]', "1", params[:search][:details] %>
        <label for="search[details]">Show comments in CSV</label>
        </td></tr>
        </tbody></table>
        </fieldset>
        <% end %>
    
<!-- End of form -->

<br/><br/>
 
<!-- List of activities -->
<%if !@activities.blank? %>    
    <fieldset>
        <legend>
        <% if params[:search].nil? %>
        Activities List
        <% else %>
        Activities List - search result
        <% end %>
        </legend>
        <%= render :partial => "list" %>
    </fieldset>
<%else%>
<p id="errorNotice">No activities found</p>
<%end%>
<!-- End of list --> 

<br/><br/>
<%= back_link %>
      
</div>   
